<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{item}}</li>
  </ul>
  <ul>
    <li v-for="item in prodArr">{{item}}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>商品编号</th>
      <th>商品标题</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in prodArr">
      <td>{{index+1}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.stock}}</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>
<script setup>
import {ref} from "vue";
const prodArr = ref([
  {title: '华为手机', price: 5000, stock: 100},
  {title: '苹果手机', price: 8000, stock: 200},
  {title: '小米手机', price: 3000, stock: 300},
  {title: '三星手机', price: 4000, stock: 400}
]);
//定义删除商品的方法
const del = (index)=>{
  if(confirm('您确认要删除本商品吗?')){
    prodArr.value.splice(index,1);
  }
}
</script>

<style scoped>

</style>